package com.mengshuai.mysql.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitmq")
public class RabbitmqController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    // 发送简单消息
    @GetMapping("/addMsg")
    public void addMsg(@RequestParam String routingKey, @RequestParam Object msg) {
        for (int i = 1; i <= 50; i++) {
            rabbitTemplate.convertAndSend(routingKey, msg.toString() + i);
        }
    }

    @GetMapping("/addFanoutExchangeMsg")
    public void addExchangeMsg(@RequestParam String fanoutExchange, @RequestParam Object msg) throws Exception {
        //参数一: 交换机名称  参数二:暂时没用 参数三: 消息内容
        rabbitTemplate.convertAndSend("fanout.exchange", "", msg);
    }
}
